import { defineConfig, loadEnv } from 'vite'
import vue from '@vitejs/plugin-vue'
// path
import path from "path"
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }) => {
  const env = loadEnv(mode, process.cwd())
  console.log('env', env)
  return {
    plugins: [vue()],
    css: {
      preprocessorOptions: {
        scss: {
          additionalData: `@import "./src/styles/var.scss";`
        },
      }
    },
    resolve: {
      alias: {
        "@": path.resolve(__dirname, 'src'),
        "@c": path.resolve(__dirname, 'src/components'),
        "@h": path.resolve(__dirname, 'src/hook'),
      }
    },
    server: {
      open: true,
      port: 8888,
      host: "0.0.0.0",
      proxy: {  // 3个位置
        [env.VITE_APP_MASK]: { // /api/api/v1/login
          target: env.VITE_APP_API,  // http://api.web-jshtml.cn/api/v1/login
          changeOrigin: true,
          rewrite: (path) => path.replace(/^\/api/, ""),  // 正则查找开头为 /api => /api/v1/login
        },
      },
    },
  }
})
